Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/error

Package Overview
Dependencies
Maintainers
18
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/error

A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.

  • 3.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2M
decreased by-2.89%
Maintainers
18
Weekly downloads
 
Created

What is @fastify/error?

The @fastify/error package is designed to provide a simple and efficient way to create custom errors in Fastify applications. It allows developers to define error constructors with default status codes and messages, making error handling more consistent and streamlined across the application.

What are @fastify/error's main functionalities?

Creating custom errors

This feature allows developers to create custom error constructors. The example demonstrates how to create a 'NotFoundError' with a default message 'Resource not found' and a status code of 404.

const createError = require('@fastify/error');
const NotFoundError = createError('NOT_FOUND', 'Resource not found', 404);
throw new NotFoundError();

Custom error properties

This feature enables adding custom properties to errors. In the example, a 'DatabaseError' is created with an additional 'code' property, which is specified when the error is thrown.

const createError = require('@fastify/error');
const DatabaseError = createError('DB_ERROR', 'Database operation failed', 500, (opts) => ({ code: opts.code }));
throw new DatabaseError({ code: 'ER_NO_SUCH_TABLE' });

Other packages similar to @fastify/error

Keywords

FAQs

Package last updated on 04 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc